<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!--edge浏览器H5兼容设置-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!--360浏览器H5兼容设置-->
    <meta name="renderer" content="webkit" />
    <title>修改器材信息</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!--导入核心文件-->
    <script src="../bootstrap3/js/holder.js"></script>
    <link href="../bootstrap3/css/bootstrap.css" rel="stylesheet" type="text/css">
    <script src="../bootstrap3/jquery-1.9.1.min.js"></script>
    <script src="../bootstrap3/js/bootstrap.js"></script>
    <!-- 字体图标 -->
    <link rel="stylesheet" href="../bootstrap3/font-awesome-4.7.0/css/font-awesome.css" />

    <script src="../bootstrap3/js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>


    <link rel="stylesheet" type="text/css" href="../css/equChange.css"/>

</head>
<body>
<!--网页最上方的留白-->
<header>
    <!-- class.container 容器定位 的作用是进行居中布局 -->
    <div class="container">
        <!-- pull-right 向右对齐  -->
        <span class="pull-right"><small>Sports  Equipment</small> <b>Management</b>System</span>
    </div>
</header>
<!--网页 导航栏 在layout.css 文件中设置背景图片-->
<nav>
    <!-- class.container 容器定位 用于设置内容居中 -->
    <div class="container">
        <h1>
            <b>体育器材管理系统</b> <small>——Design by Z</small>
        </h1>

        <!--导航栏-->
        <div>
            <!-- class="nav navbar-nav" 定义导航条 -->
            <ul class="nav navbar-nav">
                <li><a href="home.html">首页</a></li>
                <li><a id="back" >返回</a></li>

            </ul>
            <!-- class="nav navbar-nav" 定义导航条 向右侧浮动 -->
            <ul class="nav navbar-nav navbar-right">
                <!-- 导航条中的文字使用 class="navbar-text" 样式 -->
                <li><span class="navbar-text"></span></li>
                <li><a id="loginout"><span class="glyphicon glyphicon-off" aria-hidden="true"></span></a></li>
            </ul>
        </div>
        <!-- /导航栏 -->
    </div>
</nav>
<section>
    <br>
    <div class="container">
        <div class="row">
            <div class="col-md-4"></div>
            <div class="col-md-4">
                <form id="form-info" class="form-horizontal" role="form">
                    <div class="form-group">
                        <label class="col-md-3 col-sm-3 control-label" for="id">记录编号：</label>
                        <div class="col-md-8 col-sm-8">
                            <input type="text" class="form-control1" id="id" name="id" disabled="disabled">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 col-sm-3 control-label" for="ename">器材名称：</label>
                        <div class="col-md-8 col-sm-8">
                            <input type="text" class="form-control1" id="ename" name="ename" placeholder="请输入器材名" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-md-3 col-sm-3 control-label" for="enumber">器材数量：</label>
                        <div class="col-md-8 col-sm-8">
                            <input type="text" class="form-control1" id="enumber" name="enumber" placeholder="请输入器材数量" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-md-3 col-sm-3 control-label" for="price">器材单价：</label>
                        <div class="col-md-8 col-sm-8">
                            <input type="text" class="form-control1" id="price" name="price" placeholder="请输入器材单价" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 col-sm-3 control-label" for="unit">计量单位：</label>
                        <div class="col-md-8 col-sm-8">
                            <input type="text" class="form-control1" id="unit" name="unit" placeholder="请输入计量单位" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 col-sm-3 control-label" for="sup">供应商：</label>
                        <div class="col-md-8 col-sm-8">
                            <input type="text" class="form-control1" id="sup" name="sup" placeholder="请输入供应商" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 col-sm-3 control-label" for="phone">供应商电话：</label>
                        <div class="col-md-8 col-sm-8">
                            <input type="text" class="form-control1" id="phone" name="phone" placeholder="请输入供应商电话" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 col-sm-3 control-label" for="address">供应商地址：</label>
                        <div class="col-md-8 col-sm-8">
                            <input type="text" class="form-control1" id="address" name="address" placeholder="请输入供应商地址" >
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 col-sm-3 control-label" for="email">供应商邮箱：</label>
                        <div class="col-md-8 col-sm-8">
                            <input type="text" class="form-control1" id="email" name="email" placeholder="请输入供应商邮箱" >
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-2 col-sm-2"></div>
                        <div class="col-md-10 col-sm-10">
                            <span>&#12288;</span>
                            <input id="btn-update" class="btn btn-primary" type="button" value="确认修改">
                            <input id="btn-del" class="btn btn-primary" type="button" value="确认删除">
                        </div>

                    </div>

                </form>
            </div>

        </div>
        <div class="col-md-4"></div>
    </div>
    <br>
</section>
<!--页脚开始-->
<!--网页底部， class.well 用于设置背景效果-->
<footer class="well">
    <!-- class.container 的作用是进行居中布局 -->
    <div class="container">
        <b>Copyright © 2020 ？？.com All Rights Reserved
            <a href="#">啥也不是</a>
            版权所有
        </b> <span class="pull-right"> <b>Version</b> 1.1.0
      </span>
    </div>
</footer>
<!--页脚结束-->
<script type="text/javascript">

    $(document).ready(function () {
        $.ajax({
            "url":"/users/loginnum",
            "type":"get",
            "dataType":"json",
            success:function (json) {
                console.log(json.data)
                if (json.data!=null){
                    $("#borrow").removeAttr("disabled")
                    $("#return").removeAttr("disabled")
                    $(".navbar-text").text("管理员："+json.data)
                }
            },
            "error":function () {
                $("input").attr("disabled",true)
                $("#ul").prepend($('<li><a href="' +'http://localhost:8080/web/login.html'+ '">'+"登录"+'</a></li>'))
                $(".navbar-text").text(" ")
            }
        })
      getnotes()
    })
    $("#loginout").bind('click',function () {
        $.ajax({
            "url":"/users/logininfo",
            "type":"get",
            "dataType":"json",
            success:function (json) {
                if (json.state == 2000) {
                    $("input").removeAttr("disabled")
                    window.location.href="login.html"
                }
            },
            "error":function () {
                $("borrow").attr("disabled",true)
                $("return").attr("disabled",true)
                $(".navbar-text").append($('<a href="' +'http://localhost:8080/web/login.html'+ '">'+"登录"+'</a>'))

            }
        })
    })

    //获取那条记录
    function getnotes(){
        $.ajax({
            "url":"/equ/getEquNotes",
            "type":"get",
            "dataType":"json",
            "success":function(json) {
                console.log(json.data)
                if (json.state==2000){
                    $("#id").val(json.data.id)
                    $("#ename").val(json.data.ename)
                    $("#enumber").val(json.data.enumber)
                    $("#unit").val(json.data.unit)
                    $("#price").val(json.data.price)
                    $("#sup").val(json.data.sup)
                    $("#phone").val(json.data.phone)
                    $("#address").val(json.data.address)
                    $("#email").val(json.data.email)
                }else{
                    alert("获取信息失败，请练习管理员")
                }
            }
        });
    }
    //删除选中记录
    $("#btn-del").click(function () {
        $.ajax({
            "url":"/equ/delEquById?id="+$("#id").val(),
            "type":"get",
            "dataType":"json",
            "success":function(json) {
                if (json.state == 2000) {
                    alert("删除成功")
                    window.location.href="insert.html"
                }


            }
        });

    })
    //修改选中记录
    $("#btn-update").click(function () {
        $.ajax({
            "url":"/equ/updateEquById?id="+$("#id").val(),
            "data":$("#form-info").serialize(),
            "type":"post",
            "dataType":"json",
            "success":function(json) {
                if (json.state==2000){
                    alert("修改成功")
                    window.location.href="insert.html"
                }


            }
        });

    })
    $("#back").bind('click',function () {
        location.href = "/web/insert.html"
    })
</script>
</body>
</html>